package jnBase
{
	import jnBase.eventdispatcher.JNEventDispatcher;
	import jnBase.view.SimpleLoading;
	
	import laya.display.Scene;
	import laya.events.EventDispatcher;
	
	public class ShiyanControl extends EventDispatcher
	{
		/**
		 *需要上传到服务器上的实验数据 不包括实验报告和实验结果
		 * 实验报告和实验结果的数据在ShiYanBaoGao.as 里面的_baoGaoData
		 */		
		protected static var shiyanServerData:Object={};
		public function ShiyanControl()
		{
			super();
			JNEventDispatcher.getInstance().on(JNEventDispatcher.CLICK_ADD_PAGE,this,showPage);
			JNEventDispatcher.getInstance().on(JNEventDispatcher.NATURAL_ADD_PAGE,this,submitTimeAndShowpage);
			JNEventDispatcher.getInstance().on(JNEventDispatcher.RE_DO,this,redo);
		}
		private function redo():void
		{
			// TODO Auto Generated method stub
			showPage();
		}
		/**
		 *切换步骤 
		 * 
		 */		
		protected function showPage():void
		{
			trace("切换页面："+(Data.currStep+1));
			Data.perStepTime=0;
			Laya.stage.setChildIndex(Scene.root,0);
		}
		/**
		 *提交步骤用时 
		 * 
		 */		
		private function submitTimeAndShowpage():void
		{
			//整个步骤完成后再提交一次数据，就是最后一个小步骤的数据信息
			if(Data.currStep>0){
				var sonstep:uint=0;
				var step:uint=Data.currStep-1;
				if(!hasSonStep(step)){//没有子步骤
					sonstep=0;
				}
				else{
					sonstep=Data.stepList[step].value.length;
				}
				trace("当前步骤完成:"+(step+1)+"*"+sonstep+"用时："+Data.perStepTime);
				if(Data.token){
					Api.AddStep(Data.operationType,Data.PracticeId,(step+1)+"*"+sonstep,Data.UsedTime,0,Data.perStepTime,this,function(res):void{
						if(res.success){
							loading.close();
							showPage();
						}
					});
					//					http.send(Data.HttpRequest+"Experiment/AddStep","PracticeId="+Data.PracticeId+"&stepId="+(step+1)+"*"+sonstep+"&ExamDuration="+Data.perStepTime+"&Code="+Data.token+'&UsedTime='+Data.UsedTime,"post");
					var loading:SimpleLoading=new SimpleLoading();
					loading.show();
				}
				else {
					showPage();
				}
			}
			else{
				showPage();
			}
			
		}
		public static function hasSonStep($ind:int):Boolean
		{
			if($ind<0 || Data.stepList.length<1){
				return false;
			}
			else if(Data.stepList[$ind].value.length>0){//有二级步骤
				return true;
			}
			else return false;
		}
	}
}
